<?php if(!defined('IN_APP')) exit('Access Denied');?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
	<meta charset="UTF-8">
	<title>交易所</title>
	<meta name="description" content="">
	<meta name="keywords" content="">
	<meta name="viewport" content="initial-scale=1, width=device-width, maximum-scale=1, user-scalable=no">
	<meta name="format-detection" content="telephone=no,email=no,adress=no" />
	<meta name="apple-mobile-web-app-capable" content="yes" />  
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<link rel="stylesheet" href="<?php echo THEME_PATH;?>styles/swiper.min.css">
	<link rel="stylesheet" href="<?php echo THEME_PATH;?>styles/reset.css">
	<link rel="stylesheet" href="<?php echo THEME_PATH;?>styles/common.css">
	<link rel="stylesheet" href="<?php echo THEME_PATH;?>styles/style.css">
	<script src="<?php echo THEME_PATH;?>js/jquery-1.8.3.min.js"></script>
	<script src="<?php echo THEME_PATH;?>js/swiper.min.js"></script>
	<script type="text/javascript" src="<?php echo THEME_PATH;?>js/Validform_v5.3.2_min.js"></script>
	<script src="/statics/js/layer/layer.js"></script>
</head>
<body>
	<div class="deal-head">
		<ul class="present-price">
			<li>当前价格</li>
			<li class="num"><?php echo round($info['price'],2); ?></li>
			<li>CNY</li>
		</ul>
		<div class="chart-wrap">
			<ul class="flex flex-pack-justify chart-top">
				<li class="red">今日最高 <?php echo round($info['max_price'],2); ?> CNY</li>
				<li class="green">今日最低 <?php echo round($info['min_price'],2); ?>CNY</li>
			</ul>
			<!-- 趋势图 -->

			<div class="chart">
				<p class="title">GF价格线</p>
				<script src="https://img.hcharts.cn/highcharts/highcharts.js"></script>
				<script src="https://img.hcharts.cn/highcharts/modules/exporting.js"></script>
				<script src="https://img.hcharts.cn/highcharts-plugins/highcharts-zh_CN.js"></script>
				<div class="index-chart">
				<div id="container" style="height:200px;min-width:300px"></div>
				</div>
			</div>
		</div>
	</div>

	<div class="deal-buy-wrap">
		<!-- S 公告 -->
		<div class="notice-wrap flex">
			<i class="iconfont">&#xe69c;</i>
			<div id="announcement" class="swiper-container flex-1">
				<div class="swiper-wrapper">
					<?php foreach($records as $key => $value){
						$username = str_replace(substr($value['username'],3,4),'****',$value['username']);
						echo '<div class="swiper-slide"><a href="#">恭喜'.$username.'喜中'.$value['reward_prize'].'升值链</a></div>';
					}?>
				</div>
			</div>
			<i class="iconfont">&#xe6a0;</i>
		</div>



		<!-- E 公告 -->
		<div class="buy-sale-wrap">


			<div class="flex buy-price">
				<span class="minus" id="reduce_price">-</span>
				<div class="flex-1 flex input-box">
					<label>单价</label>
					<input type="text" value="2" class="flex-1" name="price" id="input_add_price" datatype="n">
				</div>
				<span class="add" id="add_price">+</span>
			</div>




			<div class="flex buy-price buy-amount">
				<span class="minus" id="reduce_num">-</span>
				<div class="flex-1 flex input-box">
					<label>数量</label>
					<input type="text" value="1" class="flex-1" namespace name="num" id="input_add_num">
				</div>
				<span class="add" id="add_num">+</span>
			</div>


			<ul class="flex flex-pack-justify income-usable-wrap">
				<li>预计收入 <span class="number">0.00%</span></li>
				<li>可用 <span class="number"><?php echo $userInfo['upvaluation']; ?></span>GF</li>
			</ul>
			<ul class="buy-sale-btns flex flex-pack-justify">
				<li><a href="javascript:;" class="buy_upvaluation">买入</a></li>
				<li><a href="javascript:;" class="sell_upvaluation">卖出</a></li>
			</ul>
		</div>
	</div>





	<!-- 横向菜单 -->
	<ul class="zsContMenu clearfix">
		<?php 
			if($type == 'buy'){
				echo '<li class="on"><a href="javascript:;" class="buy">求购列表</a></li>
					<li><a href="javascript:;" class="sell">出售列表</a></li>';
			}else{
				echo '<li><a href="javascript:;" class="buy">求购列表</a></li>
					<li class="on"><a href="javascript:;" class="sell">出售列表</a></li>';
			}
		
		?>
	</ul>
	<!--切换内容-->
	<div class="zsCont">
	    <!--标签1 对应展示 内容-->
	    <div class="item">
	    	<div class="flex search-wrap">
				<div class="icon-search"><img src="<?php echo THEME_PATH;?>images/icon-search.png" alt="" width="18"></div>
				<form action="<?php echo '/index.php?m=user&c=trade&a=index&type='.$type; ?>" method="post" class="form1">
					<input type="text" placeholder="请输入账号" class="flex-1 keyword1" name="keyword">
					<a href="javascript:;" class="search-btn search-btn1">搜索</a>
				</form>
	    	</div>
	    	<ul class="deal-buy-item-wrap">
				<?php if($list) : ?>
						<?php foreach($list as $key => $value) : ?>
							<li class="deal-buy-item">
									<div class="deal-user-wrap">
										<img src="<?php echo $value['photo']; ?>" alt="" width="50" height="50" class="user-img">
										<span class="user-name"><?php echo $value['real_name']; ?></span>
									</div>
									<div class="flex flex-pack-justify deal-cny-box">
										<dl>
											<dt><?php echo $value['number'] ?></dt>
											<dd>数量(GF)</dd>
										</dl>
										<dl class="alignC">
											<dt><?php echo $value['all_price'] ?></dt>
											<dd>总价(CNY)</dd>
										</dl>
										<a href="javascript:;" class="sell-btn" onclick="sell(<?php echo $value['id']; ?>)"><?php ?> 
											<?php if($type == 'buy') : ?>
												出售 </a>
											<?php else : ?>
												购买 </a>
											<?php endif ?>
									</div>
									<ul class="flex flex-pack-justify deal-infos">
										<li>成交量&nbsp;<?php echo $value['num']; ?>单&nbsp;&nbsp;&nbsp;好评率&nbsp;<?php echo $value['good_evaluate_percent']; ?>%</li>
										<li>发布时间:<?php echo $value['add_time']; ?></li>
									</ul>				
								</li>
							<?php endforeach ?>
				<?php else: ?>
				<?php endif ?>
			</ul>
			<p class="no-more">没有更多了</p>
		</div>
		
	

	 
	</div>



	<!-- S footer -->
	<div class="footBox">
		<footer>
			<a href="/index.php?m=user&c=trade&a=index&type=buy" class="cur">
				<i class="iconfont">&#xe69d;</i>
				<span>交易所</span>
			</a>
			<a href="/index.php?m=user&c=exchange&a=index">
				<i class="iconfont">&#xe69a;</i>
				<span>兑换</span>
			</a>
			<a href="/index.php?m=user&c=goods&a=index">
				<i class="iconfont">&#xe69e;</i>
				<span>商城</span>
			</a>
			<a href="/index.php?m=user&c=order&a=index">
				<i class="iconfont">&#xe69b;</i>
				<span>订单</span>
			</a>
			<a href="/index.php?m=user&c=home&a=index">
				<i class="iconfont">&#xe6a3;</i>
				<span>我的</span>
			</a>
		</footer>
	</div>
	<!-- E footer -->
<!-- 	
	<script src="<?php echo THEME_PATH;?>js/jquery-1.8.3.min.js"></script>
	<script src="<?php echo THEME_PATH;?>js/swiper.min.js"></script> -->
	<script>
		//公告
		var announcementSwiper = new Swiper('#announcement', {
		        direction: 'vertical',
				loop: true,
		        autoplay:1000
		    })

	</script>
	<script>
		 // 曲线图
		 	var sell_days = <?php echo json_encode($sell_days) ?>;
			//  console.log(sell_days);
			var serdata  = <?php echo json_encode($series); ?>;
			var chart = Highcharts.chart('container',{
				chart: {
					type: 'area'
				},
				credits:{
					enabled: false // 禁用版权信息
				},
				exporting:{
					enabled: false // 禁用到处模块
				},
				legend: {
					enabled:false,
					layout: 'vertical',
					align: 'center',
					verticalAlign: 'top',
					x: 0,
					floating: true,
					//borderWidth: 1,
					backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
				},
				title: {
					text: ''
				},
				xAxis: {
					allowDecimals: false,
					categories: sell_days,
				},
				yAxis: {
					title: {
						text: ''
					}
				},
				tooltip: {
					pointFormat: '{series.name}<b>{point.y}</b>'
				},
				plotOptions: {
					area: {
						fillOpacity: 0.3
					}
				},
				series:serdata
			});




	function tab(menus, conts) {
		$(menus).click(function() {
			var value = $(this).children().attr('class');
			// var value = "<?php echo $type; ?>";
			var index = $(this).index();
			$(this).addClass("on").siblings().removeClass("on");
			// $(conts).eq(index).removeClass("hide").siblings().addClass("hide");
			
			if(value == 'buy'){
				location.href="/index.php?m=user&c=trade&a=index&type=buy";
				// return;
			}else{
				location.href="/index.php?m=user&c=trade&a=index&type=sell";
				// return;
			}
		})
	}
	tab(".zsContMenu li", ".zsCont .item")

	$('.icon-search').click(function(){
		// console.log(111);
		if(!$('.keyword1').val()){
			// layer.msg('请输入要搜索的内容',{icon:1});
			layer.msg('请输入要搜索的内容');
			return;
		}
		$('.form1').submit();
	});

	



	// 加加减减
	$('#reduce_price').click(function(){
	
		var price = $('#input_add_price').val();
		if(price >= 1){
			$('#input_add_price').val(price-1);
		}
	})
	$('#add_price').click(function(){
		var price = parseInt($('#input_add_price').val());
		price = price +1;
		$('#input_add_price').val(price);
	})

	$('#reduce_num').click(function(){
		var price = $('#input_add_num').val();
		if(price >= 1){
			$('#input_add_num').val(price-1);
		}
	})
	$('#add_num').click(function(){

		var price = parseInt($('#input_add_num').val());
		price = price +1;
		$('#input_add_num').val(price);
	})

	
	$('.buy_upvaluation').click(function(){
		var price = $('#input_add_price').val();
		var num = $('#input_add_num').val();
		
		var type = 'buy';

		var reg = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/;
		var reg1 = /^\+?[1-9][0-9]*$/;
		if(!reg.test(price) || !price){
			layer.msg('请输入正确格式的单价');
			
			return;
		}
		if(!num || !reg1.test(num)){
			layer.msg('请输入正确格式的数量');
			return;
		}
		
		layer.confirm('确定要购买吗?', {btn: ['是','否'] }, function(index){
			$.ajax({
				url:"/index.php/?m=user&c=trade&a=deal_trade",
				type:'post',
				data:{price:price,num:num,type:type},
				dataType:'json',
				success:function(data){
			
					if(data.status ==0){
						layer.msg(data.info);
					}else{
						layer.msg(data.info);
					}
				}
			})	
			layer.close(index);
		});
		
	})

	$('.sell_upvaluation').click(function(){
		var price = $('#input_add_price').val();
		var num = $('#input_add_num').val();
		
		var type = 'sell';

		var reg = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/;
		var reg1 = /^\+?[1-9][0-9]*$/;
		if(!reg.test(price) || !price){
			layer.msg('请输入正确格式的单价');
			return;
		}
		if(!num || !reg1.test(num)){
			layer.msg('请输入正确格式的数量');
			return;
		}
		layer.confirm('确定要卖出吗?', {btn: ['是','否'] }, function(index){
			$.ajax({
				url:"/index.php/?m=user&c=trade&a=deal_trade",
				type:'post',
				data:{price:price,num:num,type:type},
				dataType:'json',
				success:function(data){
	
					if(data.status ==0){
						layer.msg(data.info);
					}else{
						layer.msg(data.info);
					}
				}
			})	
			layer.close(index);
		});
	})


	function sell(id){
		console.log(id);
		var type = "<?php echo $type; ?>";
		console.log(type);
		// return false;
		
		// layer.open({
		// 	type: 1,
		// 	skin: 'layui-layer-demo', //样式类名
		// 	closeBtn: 0, //不显示关闭按钮
		// 	anim: 2,
		// 	shadeClose: true, //开启遮罩关闭
		// 	content: '内容'
		// });
		layer.confirm('确定执行此操作?', {btn: ['是','否'] }, function(index){
			// var type = 'sell';
			
			$.ajax({
				url:"/index.php/?m=user&c=trade&a=list_trade",
				type:'post',
				data:{type:type,id:id},
				dataType:'json',
				success:function(data){
					// console.log(data);
					if(data.status ==0){
						layer.msg(data.info);
					}else{
						layer.msg(data.info);
						setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
							window.location.reload();//页面刷新
						},2000);
					}
				}
			})
			layer.close(index);
		})
	}
	</script>
</body>
</html>